﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VideoLibrary;

namespace MyVideo
{
    public partial class PlayMusic : UserControl
    {
        public PlayMusic()
        {
            InitializeComponent();
            List<FileModel> list = FileInfoClass.GetFileModelList(@"D:\My Documents\My Music");
            dgvMusic.DataSource = list;
            WMPLib.IWMPPlaylist playList = axWindowsMediaPlayer1.playlistCollection.newPlaylist("mylist");
            foreach (FileModel item in list)
            {
                playList.appendItem((WMPLib.IWMPMedia)this.axWindowsMediaPlayer1.newMedia(item.Path));
            }
            axWindowsMediaPlayer1.currentPlaylist = playList;
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }

        private void dgvMusic_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //var a = axWindowsMediaPlayer1.currentPlaylist.get_Item(3);
            //axWindowsMediaPlayer1.currentPlaylist = a;
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

        protected override void OnResize(EventArgs e)
        {
            panelEx1.Location = new Point((this.Width - panelEx1.Width) / 2, (this.Height - panelEx1.Height - 80) / 2);
            base.OnResize(e);
        }
    }
}
